package org.example.myleet.rosalind.pmch;

import org.example.myleet.rosalind.utils.BigNumberOperator;
import org.example.myleet.rosalind.utils.FastaReader;
import org.example.myleet.rosalind.utils.FastaSequence;

import java.math.BigInteger;
import java.util.List;

public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.printNumberOfPerfectMatching(">Rosalind_23\n" +
                "AGCUAGUCAU\n");
        solution.printNumberOfPerfectMatching(">Rosalind_9638\n" +
                "UGAGAAGGAGUGGGUUCUCCGGCGUAUGCAAAGAUCUUCCUAUAAGAACAACAAGCUCCA\n" +
                "UUUCAUUCGCUU\n");
    }

    public void printNumberOfPerfectMatching(String input) {
        List<FastaSequence> rnaSequences = FastaReader.parseFastaInput(input);
        FastaSequence rnaSequence = rnaSequences.get(0);
        int aCount = 0, cCount = 0;
        for (int i = 0; i < rnaSequence.getSequence().length(); ++i) {
            char c = rnaSequence.getSequence().charAt(i);
            if (c == 'A') {
                ++aCount;
            } else if (c == 'C') {
                ++cCount;
            }
        }
        BigInteger aMatchFactorial = BigNumberOperator.factorial(aCount);
        BigInteger cMatchFactorial = BigNumberOperator.factorial(cCount);
        BigInteger res = aMatchFactorial.multiply(cMatchFactorial);
        System.out.println(res);
    }
}
